<?php


class Validatie {
    private $_regexp = [
        'email'=>'^[^@]*@[^@]*\.[^@]+$i',
        'domein'=>'^[a-z]{2,3}$i'
    ];    
    
    public function email($email='') {
        $email = strtolower(trim($email));
        if (empty($email)) {
            return false;
        } else {
            /*
            $regex = $this->_regexp['email'];
            if (preg_match($regex,$email)) {
                $email = explode('.',$email);
                $domein = end($email);
                $regex = $this->_regexp['domein'];
                if (preg_math($regex,$domein)) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }*/
            if (filter_var($email,FILTER_VALIDATE_EMAIL)) {
                return true;
            } else {
                return false;
            }
        }
    }
    
    public function tekst($tekst='',$min=0,$max=9999) {
        $tekst = trim($tekst);
        if (strlen($tekst) >= $min && strlen($tekst) <= $max) {
            return true;
        } else {
            return false;
        }
    }
    
    public function string($string='',$min=0,$max=9999) {
        if (!is_string($string)) {
            return false;
        } elseif (len($string) < $min || len($string) > $max) {
            return false;
        } else {
            return true;
        }        
    }
    
    public function geheel($getal=0) {
        if (is_int($getal)) {
            return true;
        } else {
            return false;
        }
    }
    
    public function komma($getal=0) {
        if (is_float($getal)) {
            return true;
        } else {
            return false;
        }
    }
    
    public function datum($datum='') {
        $tmp = explode('-',$datum);
        $jaar = intVal($tmp[0]);
        $maand = intVal($tmp[1]);
        $dag = intVal($tmp[2]);
        
        $ok = checkdate($maand, $dag,$jaar);
        return $ok;
    }
    
    public function telefoon($telefoon='') {
        
    }
    
    public function wachtwoord($wachtwoord='') {
        if (preg_match("/^[a-zA-Z0-9?_\-]{8,}$/",$wachtwoord)) {
            $g = preg_replace('/[^A-Z]/','',$wachtwoord);
            $k = preg_replace('/[^a-z]/','',$wachtwoord);
            $c = preg_replace('/[^0-9]/','',$wachtwoord);
            if (strlen($g) > 1 && strlen($k) > 1 && strlen($c) > 1) {
                return true;
            }
        }
        return false;
    }
}
